#pragma once

#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "driver/spi_master.h"
// #include "driver/i2c_master.h"
#include "driver/i2c.h"
#include "driver/ledc.h"
#include "driver/sdmmc_host.h"
#include "driver/i2s_std.h"
#include "esp_lcd_panel_io.h"	  //new_panel_io要用到
#include "esp_lcd_panel_ops.h"	  //panel_reset..init..mirror...要用到
#include "esp_lcd_panel_vendor.h" //new_panel_st7789要用到
#include "esp_lcd_touch.h"
#include "esp_lcd_touch_ft5x06.h"
#include "esp_camera.h"
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "esp_lvgl_port.h"
#include "lvgl.h"
#include "es8311.h"

#define SW0_PIN 0

/*I2C*/
#define I2C_FREQ_HZ 100000
#define I2C_SCL_PIN 2
#define I2C_SDA_PIN 1
#define S3_I2C_NUM I2C_NUM_0

#define PCA9557_ADDR 0x19
#define PCA9557_INPUT_PORT 0x00
#define PCA9557_OUTPUT_PORT 0x01
#define PCA9557_POLARITY_INVERSION_PORT 0x02
#define PCA9557_CONFIGURATION_PORT 0x03

#define LCD_CS_GPIO BIT(0)	 // PCA9557_GPIO_NUM_1
#define PA_EN_GPIO BIT(1)	 // PCA9557_GPIO_NUM_2
#define DVP_PWDN_GPIO BIT(2) // PCA9557_GPIO_NUM_3

/*SPILCD*/
#define LCD_V_RES 240
#define LCD_H_RES 320

#define SPI_LCD_HOST SPI3_HOST
#define LCD_MOSI_PIN 40
#define LCD_CLK_PIN 41
#define LCD_DC_PIN 39
#define LCD_BL_PIN 42

/*camera*/
#define CAM_PIN_PWDN -1	 // power down is not used
#define CAM_PIN_RESET -1 // software reset will be performed
#define CAM_PIN_XCLK 5
#define CAM_PIN_SIOD 1
#define CAM_PIN_SIOC 2

#define CAM_PIN_D7 9
#define CAM_PIN_D6 4
#define CAM_PIN_D5 6
#define CAM_PIN_D4 15
#define CAM_PIN_D3 17
#define CAM_PIN_D2 8
#define CAM_PIN_D1 18
#define CAM_PIN_D0 16
#define CAM_PIN_VSYNC 3
#define CAM_PIN_HREF 46
#define CAM_PIN_PCLK 7

#define XCLK_FREQ_HZ 24000000

/*SD Card*/
#define SD_CLK_PIN 47
#define SD_CMD_PIN 48
#define SD_D0_PIN 21

/*I2S*/
#define I2S_NUM 0
#define I2S_MCLK_PIN 38
#define I2S_BCLK_PIN 14
#define I2S_WS_PIN 13
#define I2S_DO_PIN 45
#define I2S_DI_PIN -1

extern esp_lcd_panel_handle_t lcd_panel_handle;
extern i2s_chan_handle_t tx_handle;

esp_err_t test(void);
esp_err_t i2c_init(void);
void PCA9557_Init(void);
esp_err_t lcd_init(void);
void lcd_touch_init(void);
void lv_start(void);
esp_err_t camera_init();
esp_err_t camera_capture();
esp_err_t sd_init();
esp_err_t es8311_codec_init();
esp_err_t i2s_driver_init();
